fn  digit_to_char(digit: u32) -> Option<char> {
    match digit {
        10 => Some('a'),
        11 => Some('b'),
        12 => Some('c'),
        13 => Some('d'),
        14 => Some('e'),
        15 => Some('f'),
        _ => {None}
    }
}
fn char_to_digit(c: char) -> Option<u32> {
    match c {
        '1' => Some(1),
        '2' => Some(2),
        '3' => Some(3),
        '4' => Some(4),
        '5' => Some(5),
        '6' => Some(6),
        '7' => Some(7),
        '8' => Some(8),
        '9' => Some(9),
        'a' => Some(10),
        'b' => Some(11),
        'c' => Some(12),
        'd' => Some(13),
        'e' => Some(14),
        'f' => Some(15),
        _ => {None}
    }
}

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // TODO: 这里写逻辑


    let mut str_blass = String::new();
    let mut base =0;
    let mut flag = 0;
    let mut res = 0;
    for item in num_str.chars().rev(){
        if item == ')' {
            flag += 1;
            continue;
        }
        if item == '(' {
            break;
        }
        if flag == 1 {
            str_blass.push(item.clone());
        }

    }

    for item in str_blass.chars().rev() {
        if item >= 'a' && item <= 'z' {
            base = char_to_digit(item).unwrap();
            break;
        }
        base = base * 10 + item as u32 - '0' as u32;
    }

    // Obtain the original number's radix

    for item in num_str.chars() {
        if item == '(' {
            break;
        }
        res = res  *  base + item as u32 - '0' as u32;
    }

    // convert to the target radix


    // println!("res:{} base:{}",res,base);

    let mut ans = String::new();

    while res > 0 {
        let tmp_num = res % to_base;
        res = res / to_base;
        if tmp_num > 10 {
            if let Some(c) = digit_to_char(tmp_num) {
                ans.push(c.clone());
            } else {
                // to do
            }
        }else {

            ans.push(String::from(tmp_num.clone().to_string()).parse().unwrap());
        }
    }
    // println!("num_str:{} ans : {}", num_str, ans.chars().rev().collect::<String>());
    ans.chars().rev().collect()
}
